package luo.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * @Description:
 * @Author:let_free
 * @Date:2024/6/14/15:46
 **/
@Configuration
@EnableSwagger2
public class Knife4jConfig {
//    设置文档的基本信息标题信息
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("集成Knife4j实现API测试")
                .contact(new Contact("let_free", "https://www.baidu.com", "luofan_letfree@qq.com"))
                .version("1.0")
                .description("测试API")
                .build();
    }
    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
//                启动生成文档
                .enable(true)
//                设置文档基本信息为我们上面的ApiInfo
                .apiInfo(apiInfo())
                .select()
//                第一种方式  指定具体的包下面的类才会显示api
//                .apis(RequestHandlerSelectors.basePackage("luo.controller"))
//                第二种方式 只有携带ApiOperation注解的类才会生成接口文档
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
//                过滤api 这里设置所有的api都能显示
                .paths(PathSelectors.any())
                .build();
    }
}
